package com.kfm.hotel.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotNull;


/**
 * 
 * @TableName sys_user
 */
@TableName(value ="sys_user")
@Data
@NoArgsConstructor
//@RequiredArgsConstructor
@AllArgsConstructor
@ApiModel(value = "SysUser", description = "用户表")
public class SysUser implements Serializable, UserDetails {
    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "id, 主键")
//    @NonNull
    private Integer id;

    /**
     * 用户名
     */
    @ApiModelProperty(value = "username, 用户名")
    private String username;

    /**
     * 邮箱
     */
    @TableField(exist = false)
    private String email;

    /**
     * 密码，使用MD5 + SLAT
     */
    @ApiModelProperty(value = "password, 密码，使用MD5 + SLAT")
    private String password;

    /**
     * 真实姓名
     */
    private String name;

    /**
     * 手机号
     */
    private String phone;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 状态 1 正常
     */
    private Integer state;

    /**
     * 逻辑删除 1已删除
     */
    private Boolean isDel;

    /**
     * 密码解密 AES key
     */
    @TableField(exist = false)
    private String key;

    /**
     *  记住我
     */
    @TableField(exist = false)
    private Boolean rememberMe;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;


    /**
     * 用于批量删除
     */
    public SysUser(Integer id) {
        this.id = id;
        this.isDel = true;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true; // 账户是否过期
    }

    @Override
    public boolean isAccountNonLocked() {
        return true; // 账户是否锁定
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true; // 密码是否过期
    }

    @Override
    public boolean isEnabled() {
        return true; // 账户是否可用
    }
}